<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="Ast_iterator.html">
<link rel="next" href="Asttypes.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Arg" rel="Chapter" href="Arg.html">
<link title="Arg_helper" rel="Chapter" href="Arg_helper.html">
<link title="Array" rel="Chapter" href="Array.html">
<link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html">
<link title="Ast_helper" rel="Chapter" href="Ast_helper.html">
<link title="Ast_invariants" rel="Chapter" href="Ast_invariants.html">
<link title="Ast_iterator" rel="Chapter" href="Ast_iterator.html">
<link title="Ast_mapper" rel="Chapter" href="Ast_mapper.html">
<link title="Asttypes" rel="Chapter" href="Asttypes.html">
<link title="Attr_helper" rel="Chapter" href="Attr_helper.html">
<link title="Bigarray" rel="Chapter" href="Bigarray.html">
<link title="Buffer" rel="Chapter" href="Buffer.html">
<link title="Builtin_attributes" rel="Chapter" href="Builtin_attributes.html">
<link title="Bytes" rel="Chapter" href="Bytes.html">
<link title="BytesLabels" rel="Chapter" href="BytesLabels.html">
<link title="Callback" rel="Chapter" href="Callback.html">
<link title="CamlinternalFormat" rel="Chapter" href="CamlinternalFormat.html">
<link title="CamlinternalFormatBasics" rel="Chapter" href="CamlinternalFormatBasics.html">
<link title="CamlinternalLazy" rel="Chapter" href="CamlinternalLazy.html">
<link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html">
<link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html">
<link title="Ccomp" rel="Chapter" href="Ccomp.html">
<link title="Char" rel="Chapter" href="Char.html">
<link title="Clflags" rel="Chapter" href="Clflags.html">
<link title="Complex" rel="Chapter" href="Complex.html">
<link title="Condition" rel="Chapter" href="Condition.html">
<link title="Config" rel="Chapter" href="Config.html">
<link title="Consistbl" rel="Chapter" href="Consistbl.html">
<link title="Depend" rel="Chapter" href="Depend.html">
<link title="Digest" rel="Chapter" href="Digest.html">
<link title="Docstrings" rel="Chapter" href="Docstrings.html">
<link title="Dynlink" rel="Chapter" href="Dynlink.html">
<link title="Ephemeron" rel="Chapter" href="Ephemeron.html">
<link title="Event" rel="Chapter" href="Event.html">
<link title="Filename" rel="Chapter" href="Filename.html">
<link title="Format" rel="Chapter" href="Format.html">
<link title="Gc" rel="Chapter" href="Gc.html">
<link title="Genlex" rel="Chapter" href="Genlex.html">
<link title="Graphics" rel="Chapter" href="Graphics.html">
<link title="GraphicsX11" rel="Chapter" href="GraphicsX11.html">
<link title="Hashtbl" rel="Chapter" href="Hashtbl.html">
<link title="Identifiable" rel="Chapter" href="Identifiable.html">
<link title="Int32" rel="Chapter" href="Int32.html">
<link title="Int64" rel="Chapter" href="Int64.html">
<link title="Lazy" rel="Chapter" href="Lazy.html">
<link title="Lexer" rel="Chapter" href="Lexer.html">
<link title="Lexing" rel="Chapter" href="Lexing.html">
<link title="List" rel="Chapter" href="List.html">
<link title="ListLabels" rel="Chapter" href="ListLabels.html">
<link title="Location" rel="Chapter" href="Location.html">
<link title="Longident" rel="Chapter" href="Longident.html">
<link title="Map" rel="Chapter" href="Map.html">
<link title="Marshal" rel="Chapter" href="Marshal.html">
<link title="Misc" rel="Chapter" href="Misc.html">
<link title="MoreLabels" rel="Chapter" href="MoreLabels.html">
<link title="Mutex" rel="Chapter" href="Mutex.html">
<link title="Nativeint" rel="Chapter" href="Nativeint.html">
<link title="Numbers" rel="Chapter" href="Numbers.html">
<link title="Obj" rel="Chapter" href="Obj.html">
<link title="Oo" rel="Chapter" href="Oo.html">
<link title="Parse" rel="Chapter" href="Parse.html">
<link title="Parser" rel="Chapter" href="Parser.html">
<link title="Parsetree" rel="Chapter" href="Parsetree.html">
<link title="Parsing" rel="Chapter" href="Parsing.html">
<link title="Pervasives" rel="Chapter" href="Pervasives.html">
<link title="Pparse" rel="Chapter" href="Pparse.html">
<link title="Pprintast" rel="Chapter" href="Pprintast.html">
<link title="Printast" rel="Chapter" href="Printast.html">
<link title="Printexc" rel="Chapter" href="Printexc.html">
<link title="Printf" rel="Chapter" href="Printf.html">
<link title="Profile" rel="Chapter" href="Profile.html">
<link title="Queue" rel="Chapter" href="Queue.html">
<link title="Random" rel="Chapter" href="Random.html">
<link title="Scanf" rel="Chapter" href="Scanf.html">
<link title="Set" rel="Chapter" href="Set.html">
<link title="Simplif" rel="Chapter" href="Simplif.html">
<link title="Sort" rel="Chapter" href="Sort.html">
<link title="Spacetime" rel="Chapter" href="Spacetime.html">
<link title="Stack" rel="Chapter" href="Stack.html">
<link title="StdLabels" rel="Chapter" href="StdLabels.html">
<link title="Str" rel="Chapter" href="Str.html">
<link title="Stream" rel="Chapter" href="Stream.html">
<link title="String" rel="Chapter" href="String.html">
<link title="StringLabels" rel="Chapter" href="StringLabels.html">
<link title="Strongly_connected_components" rel="Chapter" href="Strongly_connected_components.html">
<link title="Syntaxerr" rel="Chapter" href="Syntaxerr.html">
<link title="Sys" rel="Chapter" href="Sys.html">
<link title="Targetint" rel="Chapter" href="Targetint.html">
<link title="Tbl" rel="Chapter" href="Tbl.html">
<link title="Terminfo" rel="Chapter" href="Terminfo.html">
<link title="Thread" rel="Chapter" href="Thread.html">
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
<link title="Typemod" rel="Chapter" href="Typemod.html">
<link title="Uchar" rel="Chapter" href="Uchar.html">
<link title="Unix" rel="Chapter" href="Unix.html">
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
<link title="Warnings" rel="Chapter" href="Warnings.html">
<link title="Weak" rel="Chapter" href="Weak.html"><link title="A generic Parsetree mapper" rel="Section" href="#1_AgenericParsetreemapper">
<link title="Apply mappers to compilation units" rel="Section" href="#1_Applymapperstocompilationunits">
<link title="Registration API" rel="Section" href="#1_RegistrationAPI">
<link title="Convenience functions to write mappers" rel="Section" href="#1_Conveniencefunctionstowritemappers">
<link title="Helper functions to call external mappers" rel="Section" href="#1_Helperfunctionstocallexternalmappers">
<link title="Cookies" rel="Section" href="#1_Cookies">
<title>Ast_mapper</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Ast_iterator.html" title="Ast_iterator">Previous</a>
&nbsp;<a class="up" href="index.html" title="Index">Up</a>
&nbsp;<a class="post" href="Asttypes.html" title="Asttypes">Next</a>
</div>
<h1>Module <a href="type_Ast_mapper.html">Ast_mapper</a></h1>

<pre><span id="MODULEAst_mapper"><span class="keyword">module</span> Ast_mapper</span>: <code class="code"><span class="keyword">sig</span></code> <a href="Ast_mapper.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<div class="info-desc">
<p>The interface of a -ppx rewriter</p>

<p>A -ppx rewriter is a program that accepts a serialized abstract syntax
  tree and outputs another, possibly modified, abstract syntax tree.
  This module encapsulates the interface between the compiler and
  the -ppx rewriters, handling such details as the serialization format,
  forwarding of command-line flags, and storing state.</p>

<p><a href="Ast_mapper.html#TYPEmapper"><code class="code"><span class="constructor">Ast_mapper</span>.mapper</code></a> allows to implement AST rewriting using open recursion.
  A typical mapper would be based on <a href="Ast_mapper.html#VALdefault_mapper"><code class="code"><span class="constructor">Ast_mapper</span>.default_mapper</code></a>, a deep
  identity mapper, and will fall back on it for handling the syntax it
  does not modify. For example:</p>

<pre class="codepre"><code class="code"><span class="keyword">open</span> <span class="constructor">Asttypes</span>
<span class="keyword">open</span> <span class="constructor">Parsetree</span>
<span class="keyword">open</span> <span class="constructor">Ast_mapper</span>

<span class="keyword">let</span> test_mapper argv =
  { default_mapper <span class="keyword">with</span>
    expr = <span class="keyword">fun</span> mapper expr <span class="keywordsign">-&gt;</span>
      <span class="keyword">match</span> expr <span class="keyword">with</span>
      <span class="keywordsign">|</span> { pexp_desc = <span class="constructor">Pexp_extension</span> ({ txt = <span class="string">"test"</span> }, <span class="constructor">PStr</span> [])} <span class="keywordsign">-&gt;</span>
        <span class="constructor">Ast_helper</span>.<span class="constructor">Exp</span>.constant (<span class="constructor">Const_int</span> 42)
      <span class="keywordsign">|</span> other <span class="keywordsign">-&gt;</span> default_mapper.expr mapper other; }

<span class="keyword">let</span> () =
  register <span class="string">"ppx_test"</span> test_mapper</code></pre>
<p>This -ppx rewriter, which replaces <code class="code">[%test]</code> in expressions with
  the constant <code class="code">42</code>, can be compiled using
  <code class="code">ocamlc&nbsp;-o&nbsp;ppx_test&nbsp;-<span class="constructor">I</span>&nbsp;+compiler-libs&nbsp;ocamlcommon.cma&nbsp;ppx_test.ml</code>.</p>
</div>
</div>
<hr width="100%">
<h2 id="1_AgenericParsetreemapper">A generic Parsetree mapper</h2>
<pre><code><span id="TYPEmapper"><span class="keyword">type</span> <code class="type"></code>mapper</span> = {</code></pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.attribute">attribute</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a> -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.attributes">attributes</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a> list -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a> list</code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.case">case</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEcase">Parsetree.case</a> -> <a href="Parsetree.html#TYPEcase">Parsetree.case</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.cases">cases</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEcase">Parsetree.case</a> list -> <a href="Parsetree.html#TYPEcase">Parsetree.case</a> list</code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_declaration">class_declaration</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEclass_declaration">Parsetree.class_declaration</a> -> <a href="Parsetree.html#TYPEclass_declaration">Parsetree.class_declaration</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_description">class_description</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEclass_description">Parsetree.class_description</a> -> <a href="Parsetree.html#TYPEclass_description">Parsetree.class_description</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_expr">class_expr</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_expr">Parsetree.class_expr</a> -> <a href="Parsetree.html#TYPEclass_expr">Parsetree.class_expr</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_field">class_field</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_field">Parsetree.class_field</a> -> <a href="Parsetree.html#TYPEclass_field">Parsetree.class_field</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_signature">class_signature</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_signature">Parsetree.class_signature</a> -> <a href="Parsetree.html#TYPEclass_signature">Parsetree.class_signature</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_structure">class_structure</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_structure">Parsetree.class_structure</a> -> <a href="Parsetree.html#TYPEclass_structure">Parsetree.class_structure</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_type">class_type</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_type">Parsetree.class_type</a> -> <a href="Parsetree.html#TYPEclass_type">Parsetree.class_type</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_type_declaration">class_type_declaration</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEclass_type_declaration">Parsetree.class_type_declaration</a> -> <a href="Parsetree.html#TYPEclass_type_declaration">Parsetree.class_type_declaration</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.class_type_field">class_type_field</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEclass_type_field">Parsetree.class_type_field</a> -> <a href="Parsetree.html#TYPEclass_type_field">Parsetree.class_type_field</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.constructor_declaration">constructor_declaration</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEconstructor_declaration">Parsetree.constructor_declaration</a> -> <a href="Parsetree.html#TYPEconstructor_declaration">Parsetree.constructor_declaration</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.expr">expr</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEexpression">Parsetree.expression</a> -> <a href="Parsetree.html#TYPEexpression">Parsetree.expression</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.extension">extension</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEextension">Parsetree.extension</a> -> <a href="Parsetree.html#TYPEextension">Parsetree.extension</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.extension_constructor">extension_constructor</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEextension_constructor">Parsetree.extension_constructor</a> -> <a href="Parsetree.html#TYPEextension_constructor">Parsetree.extension_constructor</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.include_declaration">include_declaration</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEinclude_declaration">Parsetree.include_declaration</a> -> <a href="Parsetree.html#TYPEinclude_declaration">Parsetree.include_declaration</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.include_description">include_description</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEinclude_description">Parsetree.include_description</a> -> <a href="Parsetree.html#TYPEinclude_description">Parsetree.include_description</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.label_declaration">label_declaration</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPElabel_declaration">Parsetree.label_declaration</a> -> <a href="Parsetree.html#TYPElabel_declaration">Parsetree.label_declaration</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.location">location</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Location.html#TYPEt">Location.t</a> -> <a href="Location.html#TYPEt">Location.t</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_binding">module_binding</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEmodule_binding">Parsetree.module_binding</a> -> <a href="Parsetree.html#TYPEmodule_binding">Parsetree.module_binding</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_declaration">module_declaration</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEmodule_declaration">Parsetree.module_declaration</a> -> <a href="Parsetree.html#TYPEmodule_declaration">Parsetree.module_declaration</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_expr">module_expr</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEmodule_expr">Parsetree.module_expr</a> -> <a href="Parsetree.html#TYPEmodule_expr">Parsetree.module_expr</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_type">module_type</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEmodule_type">Parsetree.module_type</a> -> <a href="Parsetree.html#TYPEmodule_type">Parsetree.module_type</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.module_type_declaration">module_type_declaration</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEmodule_type_declaration">Parsetree.module_type_declaration</a> -> <a href="Parsetree.html#TYPEmodule_type_declaration">Parsetree.module_type_declaration</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.open_description">open_description</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEopen_description">Parsetree.open_description</a> -> <a href="Parsetree.html#TYPEopen_description">Parsetree.open_description</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.pat">pat</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEpattern">Parsetree.pattern</a> -> <a href="Parsetree.html#TYPEpattern">Parsetree.pattern</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.payload">payload</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEpayload">Parsetree.payload</a> -> <a href="Parsetree.html#TYPEpayload">Parsetree.payload</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.signature">signature</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a> -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.signature_item">signature_item</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEsignature_item">Parsetree.signature_item</a> -> <a href="Parsetree.html#TYPEsignature_item">Parsetree.signature_item</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.structure">structure</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a> -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.structure_item">structure_item</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEstructure_item">Parsetree.structure_item</a> -> <a href="Parsetree.html#TYPEstructure_item">Parsetree.structure_item</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.typ">typ</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEcore_type">Parsetree.core_type</a> -> <a href="Parsetree.html#TYPEcore_type">Parsetree.core_type</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.type_declaration">type_declaration</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEtype_declaration">Parsetree.type_declaration</a> -> <a href="Parsetree.html#TYPEtype_declaration">Parsetree.type_declaration</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.type_extension">type_extension</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEtype_extension">Parsetree.type_extension</a> -> <a href="Parsetree.html#TYPEtype_extension">Parsetree.type_extension</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.type_kind">type_kind</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEtype_kind">Parsetree.type_kind</a> -> <a href="Parsetree.html#TYPEtype_kind">Parsetree.type_kind</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.value_binding">value_binding</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEvalue_binding">Parsetree.value_binding</a> -> <a href="Parsetree.html#TYPEvalue_binding">Parsetree.value_binding</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.value_description">value_description</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -><br>       <a href="Parsetree.html#TYPEvalue_description">Parsetree.value_description</a> -> <a href="Parsetree.html#TYPEvalue_description">Parsetree.value_description</a></code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTmapper.with_constraint">with_constraint</span>&nbsp;: <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a> -> <a href="Parsetree.html#TYPEwith_constraint">Parsetree.with_constraint</a> -> <a href="Parsetree.html#TYPEwith_constraint">Parsetree.with_constraint</a></code>;</code></td>

</tr></table>
}

<div class="info ">
<div class="info-desc">
<p>A mapper record implements one "method" per syntactic category,
    using an open recursion style: each method takes as its first
    argument the mapper to be applied to children in the syntax
    tree.</p>
</div>
</div>


<pre><span id="VALdefault_mapper"><span class="keyword">val</span> default_mapper</span> : <code class="type"><a href="Ast_mapper.html#TYPEmapper">mapper</a></code></pre><div class="info ">
<div class="info-desc">
<p>A default mapper, which implements a "deep identity" mapping.</p>
</div>
</div>
<h2 id="1_Applymapperstocompilationunits">Apply mappers to compilation units</h2>
<pre><span id="VALtool_name"><span class="keyword">val</span> tool_name</span> : <code class="type">unit -> string</code></pre><div class="info ">
<div class="info-desc">
<p>Can be used within a ppx preprocessor to know which tool is
    calling it <code class="code"><span class="string">"ocamlc"</span></code>, <code class="code"><span class="string">"ocamlopt"</span></code>, <code class="code"><span class="string">"ocamldoc"</span></code>, <code class="code"><span class="string">"ocamldep"</span></code>,
    <code class="code"><span class="string">"ocaml"</span></code>, ...  Some global variables that reflect command-line
    options are automatically synchronized between the calling tool
    and the ppx preprocessor: <a href="Clflags.html#VALinclude_dirs"><code class="code"><span class="constructor">Clflags</span>.include_dirs</code></a>,
    <a href="Config.html#VALload_path"><code class="code"><span class="constructor">Config</span>.load_path</code></a>, <a href="Clflags.html#VALopen_modules"><code class="code"><span class="constructor">Clflags</span>.open_modules</code></a>, <a href="Clflags.html#VALfor_package"><code class="code"><span class="constructor">Clflags</span>.for_package</code></a>,
    <a href="Clflags.html#VALdebug"><code class="code"><span class="constructor">Clflags</span>.debug</code></a>.</p>
</div>
</div>

<pre><span id="VALapply"><span class="keyword">val</span> apply</span> : <code class="type">source:string -> target:string -> <a href="Ast_mapper.html#TYPEmapper">mapper</a> -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Apply a mapper (parametrized by the unit name) to a dumped
    parsetree found in the <code class="code">source</code> file and put the result in the
    <code class="code">target</code> file. The <code class="code">structure</code> or <code class="code">signature</code> field of the mapper
    is applied to the implementation or interface.</p>
</div>
</div>

<pre><span id="VALrun_main"><span class="keyword">val</span> run_main</span> : <code class="type">(string list -> <a href="Ast_mapper.html#TYPEmapper">mapper</a>) -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Entry point to call to implement a standalone -ppx rewriter from a
    mapper, parametrized by the command line arguments.  The current
    unit name can be obtained from <a href="Location.html#VALinput_name"><code class="code"><span class="constructor">Location</span>.input_name</code></a>.  This
    function implements proper error reporting for uncaught
    exceptions.</p>
</div>
</div>
<h2 id="1_RegistrationAPI">Registration API</h2>
<pre><span id="VALregister_function"><span class="keyword">val</span> register_function</span> : <code class="type">(string -> (string list -> <a href="Ast_mapper.html#TYPEmapper">mapper</a>) -> unit) <a href="Pervasives.html#TYPEref">ref</a></code></pre>
<pre><span id="VALregister"><span class="keyword">val</span> register</span> : <code class="type">string -> (string list -> <a href="Ast_mapper.html#TYPEmapper">mapper</a>) -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Apply the <code class="code">register_function</code>.  The default behavior is to run the
    mapper immediately, taking arguments from the process command
    line.  This is to support a scenario where a mapper is linked as a
    stand-alone executable.</p>

<p>It is possible to overwrite the <code class="code">register_function</code> to define
    "-ppx drivers", which combine several mappers in a single process.
    Typically, a driver starts by defining <code class="code">register_function</code> to a
    custom implementation, then lets ppx rewriters (linked statically
    or dynamically) register themselves, and then run all or some of
    them.  It is also possible to have -ppx drivers apply rewriters to
    only specific parts of an AST.</p>

<p>The first argument to <code class="code">register</code> is a symbolic name to be used by
    the ppx driver.</p>
</div>
</div>
<h2 id="1_Conveniencefunctionstowritemappers">Convenience functions to write mappers</h2>
<pre><span id="VALmap_opt"><span class="keyword">val</span> map_opt</span> : <code class="type">('a -> 'b) -> 'a option -> 'b option</code></pre>
<pre><span id="VALextension_of_error"><span class="keyword">val</span> extension_of_error</span> : <code class="type"><a href="Location.html#TYPEerror">Location.error</a> -> <a href="Parsetree.html#TYPEextension">Parsetree.extension</a></code></pre><div class="info ">
<div class="info-desc">
<p>Encode an error into an 'ocaml.error' extension node which can be
    inserted in a generated Parsetree.  The compiler will be
    responsible for reporting the error.</p>
</div>
</div>

<pre><span id="VALattribute_of_warning"><span class="keyword">val</span> attribute_of_warning</span> : <code class="type"><a href="Location.html#TYPEt">Location.t</a> -> string -> <a href="Parsetree.html#TYPEattribute">Parsetree.attribute</a></code></pre><div class="info ">
<div class="info-desc">
<p>Encode a warning message into an 'ocaml.ppwarning' attribute which can be
    inserted in a generated Parsetree.  The compiler will be
    responsible for reporting the warning.</p>
</div>
</div>
<h2 id="1_Helperfunctionstocallexternalmappers">Helper functions to call external mappers</h2>
<pre><span id="VALadd_ppx_context_str"><span class="keyword">val</span> add_ppx_context_str</span> : <code class="type">tool_name:string -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a> -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a></code></pre><div class="info ">
<div class="info-desc">
<p>Extract information from the current environment and encode it
    into an attribute which is prepended to the list of structure
    items in order to pass the information to an external
    processor.</p>
</div>
</div>

<pre><span id="VALadd_ppx_context_sig"><span class="keyword">val</span> add_ppx_context_sig</span> : <code class="type">tool_name:string -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a> -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a></code></pre><div class="info ">
<div class="info-desc">
<p>Same as <code class="code">add_ppx_context_str</code>, but for signatures.</p>
</div>
</div>

<pre><span id="VALdrop_ppx_context_str"><span class="keyword">val</span> drop_ppx_context_str</span> : <code class="type">restore:bool -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a> -> <a href="Parsetree.html#TYPEstructure">Parsetree.structure</a></code></pre><div class="info ">
<div class="info-desc">
<p>Drop the ocaml.ppx.context attribute from a structure.  If
    <code class="code">restore</code> is true, also restore the associated data in the current
    process.</p>
</div>
</div>

<pre><span id="VALdrop_ppx_context_sig"><span class="keyword">val</span> drop_ppx_context_sig</span> : <code class="type">restore:bool -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a> -> <a href="Parsetree.html#TYPEsignature">Parsetree.signature</a></code></pre><div class="info ">
<div class="info-desc">
<p>Same as <code class="code">drop_ppx_context_str</code>, but for signatures.</p>
</div>
</div>
<h2 id="1_Cookies">Cookies</h2><p>Cookies are used to pass information from a ppx processor to
    a further invocation of itself, when called from the OCaml
    toplevel (or other tools that support cookies).</p>

<pre><span id="VALset_cookie"><span class="keyword">val</span> set_cookie</span> : <code class="type">string -> <a href="Parsetree.html#TYPEexpression">Parsetree.expression</a> -> unit</code></pre>
<pre><span id="VALget_cookie"><span class="keyword">val</span> get_cookie</span> : <code class="type">string -> <a href="Parsetree.html#TYPEexpression">Parsetree.expression</a> option</code></pre></body></html>